<template>
  <div>
    <el-row :gutter="10">
      <!-- 商品横向 -->
      <el-col :md="24" class="cart_box">
        <div class="cart_item_box" v-for="(item,index) in cartListtems" :key="index">
          <div>
            <input type="checkbox" @click="checkbox(item)" :checked="item.checked" />
          </div>
          <div>
            <img :src="item.productImage" width="80px" height="80px" />
            <p>{{item.productName}}</p>
          </div>
          <div>￥：{{item.salePrice}}</div>
          <div>
            <van-stepper v-model="item.count" @change="saveNum" />
          </div>
          <div>单品总价：{{item.count*item.salePrice}}</div>
          <div>
            <van-icon name="delete" @click="dele(index)" />
          </div>
        </div>
      </el-col>
    </el-row>
    <!-- 底部 -->
    <el-row :gutter="10">
      <!-- 商品横向 -->
      <el-col :md="24">
        <div class="cart_item_footer">
          <div>
            <input type="checkbox" :checked="checkboxList" @click="checkAll" />全选
          </div>
          <div>
            <p>总价：{{Allprices | spliceText}}</p>
          </div>
          <div>
            <button>结算</button>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: ""
    };
  },
  computed: {
    cartListtems() {
      return this.$store.state.cartListtems;
    },
    checkboxList() {
      return this.$store.state.checkboxList;
    },
    Allprices() {
      return this.$store.state.Allprices;
    },
  },
  methods: {
    // 删除
    dele(index) {
      this.$store.dispatch("DELEITEM", index);
      console.log(index);
    },
    checkbox(item) {
      this.$store.dispatch("CHECKBOX", item);
    },
    //全选
    checkAll($event) {
      console.log($event.target.checked);

      this.$store.dispatch("CHECKALL", $event.target.checked);
    },
    // 计步器
    saveNum() {
      localStorage.setItem(
        "cartListtems",
        JSON.stringify(this.$store.state.cartListtems)
      );
    }
  },
  filters: {
    spliceText(value){
      return value.toFixed(2);
    },
  }
};
</script>

<style  scoped>
.cart_item_box {
  background: #99a9bf;
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-bottom: 1px solid white;
}
.cart_box {
  margin-bottom: 40px;
}

.cart_item_box > div:nth-child(2) p {
  font-size: 13px;
  font-weight: 600;
}
.cart_item_footer {
  height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  background: white;
  display: flex;
  align-items: center;
}
.cart_item_footer > div:nth-child(1) {
  width: 18%;
}
.cart_item_footer > div:nth-child(2) {
  width: 70%;
  text-align: right;
}
.cart_item_footer > div:nth-child(3) {
  width: 10%;
}
.cart_item_footer > div:nth-child(3) button {
  background: red;
  color: white;
  height: 40px;
  border: 0;
  width: 100%;
}
</style>